package kr.hkit.androidcomplete01.ch06;

import kr.hkit.androidcomplete01.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;

public class SetParameterEx extends Activity {

	private Button mLeftBtn;
	private Button mRightBtn;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.ch06_setparameterex);
		
		mLeftBtn = (Button) findViewById(R.id.btnleft);
		mRightBtn = (Button) findViewById(R.id.btnright);
		/*mLeftBtn.setOnClickListener(listener); 
		mRightBtn.setOnClickListener(listener);*/
		
	}	
		
	//교재 방법
	/*	mLeftBtn.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				setParam(3,1);
			}
		});
		
		mRightBtn.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				setParam(1,3);
			}
		});
	}*/

	
	//리스너 달아서 한번에 ! 
		/*View.OnClickListener listener = new OnClickListener() {
			@Override
			public void onClick(View v) {
				switch(v.getId()) {
					case R.id.btnleft:
						setParam(3,1);
						break;
					case R.id.btnright:
						setParam(1,3);
						break;
				}
			}
		};
		
	}*/
		
	
	private void setParam(int left, int right) {
		LinearLayout.LayoutParams lparam = (LayoutParams) mLeftBtn.getLayoutParams();
		lparam.weight = left;
		mLeftBtn.setLayoutParams(lparam);
		
		LinearLayout.LayoutParams rparam = (LayoutParams) mRightBtn.getLayoutParams();
		rparam.weight = right;
		mRightBtn.setLayoutParams(rparam);
		
	}
	
	//xml에 onClick만 추가해주면 간단하게 끝남. View를 받음 
	public void mOnClick(View v) { // 대소문자 구분함
		switch (v.getId()) {
		case R.id.btnleft:
			setParam(3, 1);
			break;
		case R.id.btnright:
			setParam(1, 3);
			break;
		}
	}
}
